﻿using CubicFWNet.Application.SystemManager;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PagedList;
using CubicFWNet.Common;
using CubicFWNet.Data.Models;

namespace CubicFWNet.Mvc.Controllers
{
    public class AnnouncementTypeController : ControllerBase
    {
        private AnnouncementTypeApp _newstypeApp;
        // GET: LearningType
        public AnnouncementTypeController()
        {
            _newstypeApp = new AnnouncementTypeApp();
        }
        public ActionResult Index(int page = 1)
        {
            return View(_newstypeApp.GetLearningList().ToPagedList(page, 10));
        }
        [HttpPost]
        [HandlerAjaxOnly]
        public string Add(NewsType newstype)
        {
            newstype.Class = 1;
            newstype.Status = true;
            _newstypeApp.AddOrUpdate(newstype);
            return Result.ToJson();
        }

        public ActionResult GetFormJson(Guid id)
        {
            var data = _newstypeApp.GetForm(id);
            return Content(data.ToJson());
        }

        [HttpPost]
        [HandlerAjaxOnly]
        public string Delete(Guid id)
        {

            if (_newstypeApp.Delete(id) == -404)
            {
                Result.Status = "error";
                Result.Message = "未找到该数据";
            }
            return Result.ToJson();
        }
        //public ActionResult Edit()
        //{
        //    string pid = Request.QueryString["PID"];
        //    Guid id = new Guid(pid);
        //    NewsType n = _newstypeApp.GetForm(id);
        //    if (n != null)
        //    {
        //        ViewBag.Modules = _newstypeApp.GetLearningList();
        //        ViewBag.n = n;
        //    }
        //    return View();
        //}

        ///// <summary>
        ///// 产品编辑[提交表单]
        ///// </summary>
        ///// <returns></returns>
        //[HttpPost]
        //[ValidateInput(false)]
        //public ActionResult Edit(NewsType newstype)
        //{
        //    newstype.Class = 2;
        //    newstype.Status = true;
        //    if (newstype != null)
        //    {
        //        int i = _newstypeApp.Update(newstype);
        //        if (i == 1)
        //        {
        //            //return Result.ToJson();
        //            return RedirectToAction("Index", "AnnouncementType");
        //        }
        //        else
        //        {
        //            ViewBag.Info = "抱歉，添加失败！";
        //        }
        //    }
        //    return View(newstype);
        //}
    }
}